import variables from '@/styles/element-variables.scss'
import { getStorage } from '@/utils/auth'

const state = {
  theme: getStorage('theme') || variables.theme,
  fixedHeader: getStorage('fixedHeader') ? getStorage('fixedHeader') === 'true' : true,
  showSettings: false
}

const mutations = {
  CHANGE_SETTING: (state, { key, value }) => {
    if (state.hasOwnProperty(key)) {
      state[key] = value
      localStorage.setItem(key, value)
    }
  }
}

const actions = {
  changeSetting({ commit }, data) {
    commit('CHANGE_SETTING', data)
  }
}

export default {
  namespaced: true,
  state,
  mutations,
  actions
}

